/******************
Author : CR_2683
******************/
#include <bits/stdc++.h>
using namespace std;
#define nl "\n"
#define dis(x) cout<<"x= "<<x<<nl
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define pb push_back
#define all(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
void solveProblem(){
string s;
cin>>s;
ll idx1 , idx2;
for(int i=0;i<s.size();i++){
if(s[i]=='1'){
idx1=i+1;
}
if(s[i]=='3'){
idx2=i+1;
}
}
if(idx1 < idx2){
cout<<13<<endl;
}
else{
cout<<31<<endl;
}
}
int main()
{
ll test;
cin>>test;
while(test--){
solveProblem();
}
return 0;
}
454B - Little Pony and Sort by Shift | 1152A - Neko Finds Grapes |
1719B - Mathematical Circus | 1719C - Fighting Tournament |
1642A - Hard Way | 285C - Building Permutation |
1719E - Fibonacci Strings | 1696C - Fishingprince Plays With Array |
1085A - Right-Left Cipher | 1508B - Almost Sorted |
1690C - Restoring the Duration of Tasks | 1055A - Metro |
1036D - Vasya and Arrays | 1139C - Edgy Trees |
37A - Towers | 353A - Domino |
409H - A + B Strikes Back | 1262A - Math Problem |
158C - Cd and pwd commands | 194A - Exams |
1673B - A Perfectly Balanced String | 1104B - Game with string |
1169B - Pairs | 1567D - Expression Evaluation Error |
78A - Haiku | 1287A - Angry Students |
1428A - Box is Pull | 234B - Reading |
581B - Luxurious Houses | 1481C - Fence Painting |